package network.tcp.nio.http;

import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * @program: bio
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-27 19:32
 **/
public class AcceptHandler {

    public void connectSocketChannel(SelectionKey selectionKey) {

        try {
            ServerSocketChannel ssc = (ServerSocketChannel) selectionKey.channel();
            // ssc.configureBlocking(false);
            //
            SocketChannel accept = ssc.accept();
            accept.configureBlocking(false);
            //注册
            accept.register(selectionKey.selector(), SelectionKey.OP_READ);
            //当客户端来连接的时候,所有操作都全部执行完毕

            // 不要释放资源 因为还没有用,只是改了状态
            // accept.close();
            // ssc.close();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
    }
}
